*************************************************
* Purpose -- TWFE analysis using QCEW data (quarterly)
************************************************
clear all
* RUN 00_path_master.do FIRST TO GET FILEPATHS

************************************************
* Loading different samples
************************************************
* 1. CZ-state
frame create twfe1
frame change twfe1

use "$clean/qcew/cz_state_sample_qtr.dta", clear

* creating frames for sub-periods

frame copy twfe1 twfe1_00
frame copy twfe1 twfe1_16

frame twfe1_00: keep if inrange(year,2000,2016)
frame twfe1_16: keep if year <= 2016


* 2. MSCZ

frame create mscz
frame change mscz

use "$clean/qcew/mscz_sample_qtr.dta", clear

* creating frames for sub-periods
frame copy mscz mscz_00
frame copy mscz mscz_16

frame mscz_00: keep if inrange(year,2000,2016)
frame mscz_16: keep if year <= 2016


* 3. BCP

frame create bcp
frame change bcp

use "$clean/qcew/bcp_sample_qtr.dta", clear

* creating frames for sub-periods
frame copy bcp bcp_00
frame copy bcp bcp_16

frame bcp_00: keep if inrange(year,2000,2016)
frame bcp_16: keep if year <= 2016


************************************************
* TWFE regressions
************************************************

foreach frame in twfe1 twfe1_00 twfe1_16 {
	frame `frame' {
		eststo `frame'_earn_uw: reghdfe learn75 lmw learn_other lpop, a(czstate yq) cluster(statefips)
		eststo `frame'_emp_uw: reghdfe lemp75 lmw lemp_other lpop, a(czstate yq) cluster(statefips)
		eststo `frame'_owe_uw: ivreghdfe lemp75 (learn75 = lmw) learn_other lemp_other lpop, a(czstate yq) cluster(statefips)
		
		eststo `frame'_earn_w: reghdfe learn75 lmw learn_other lpop [aw=pop], a(czstate yq) cluster(statefips)
		eststo `frame'_emp_w: reghdfe lemp75 lmw lemp_other lpop [aw=pop], a(czstate yq) cluster(statefips)
		eststo `frame'_owe_w: ivreghdfe lemp75 (learn75 = lmw) learn_other lemp_other lpop [aw=pop], a(czstate yq) cluster(statefips)

		estadd local fe " "
		estadd local czp_fe " "
		estadd local bcp_fe " "
		estadd local gap " "
		estadd local samples " "
		estadd local cz_state_sample "Y"
		estadd local mscz_sample " "
		estadd local bcp_sample " "	
	}
}



foreach frame in bcp bcp_00 bcp_16 {
	frame `frame' {
		eststo `frame'_earn_uw: reghdfe learn75 lmw learn_other lpop, a(pair_id_county pair_id_num##yq) cluster(statefips)
		eststo `frame'_emp_uw: reghdfe lemp75 lmw lemp_other lpop, a(pair_id_county pair_id_num##yq) cluster(statefips)
		eststo `frame'_owe_uw: ivreghdfe lemp75 (learn75 = lmw) learn_other lemp_other lpop, a(pair_id_county pair_id_num##yq) cluster(statefips)
		
		eststo `frame'_earn_w: reghdfe learn75 lmw learn_other lpop [aw=pop], a(pair_id_county pair_id_num##yq) cluster(statefips)
		eststo `frame'_emp_w: reghdfe lemp75 lmw lemp_other lpop [aw=pop], a(pair_id_county pair_id_num##yq) cluster(statefips)
		eststo `frame'_owe_w: ivreghdfe lemp75 (learn75 = lmw) learn_other lemp_other lpop [aw=pop], a(pair_id_county pair_id_num##yq) cluster(statefips)

		estadd local fe " "
		estadd local czp_fe " "
		estadd local bcp_fe "Y"
		estadd local gap " "
		estadd local samples " "
		estadd local cz_state_sample " "
		estadd local mscz_sample " "
		estadd local bcp_sample "Y"	
	}
}



foreach frame in mscz mscz_00 mscz_16 {
	frame `frame' {
		eststo `frame'_earn_uw: reghdfe learn75 lmw learn_other lpop, a(pair_id_czstate pair_id_num##yq) cluster(statefips)
		eststo `frame'_emp_uw: reghdfe lemp75 lmw lemp_other lpop, a(pair_id_czstate pair_id_num##yq) cluster(statefips)
		eststo `frame'_owe_uw: ivreghdfe lemp75 (learn75 = lmw) learn_other lemp_other lpop, a(pair_id_czstate pair_id_num##yq) cluster(statefips)
		
		eststo `frame'_earn_w: reghdfe learn75 lmw learn_other lpop [aw=pop], a(pair_id_czstate pair_id_num##yq) cluster(statefips)
		eststo `frame'_emp_w: reghdfe lemp75 lmw lemp_other lpop [aw=pop], a(pair_id_czstate pair_id_num##yq) cluster(statefips)
		eststo `frame'_owe_w: ivreghdfe lemp75 (learn75 = lmw) learn_other lemp_other lpop [aw=pop], a(pair_id_czstate pair_id_num##yq) cluster(statefips)
		
		estadd local fe " "
		estadd local czp_fe "Y"
		estadd local bcp_fe " "
		estadd local gap " "
		estadd local samples " "
		estadd local cz_state_sample " "
		estadd local mscz_sample "Y"
		estadd local bcp_sample " "	
	}
}

* Output twfe table
esttab twfe1_earn_uw mscz_earn_uw bcp_earn_uw twfe1_16_earn_uw mscz_16_earn_uw ///
bcp_16_earn_uw twfe1_00_earn_uw mscz_00_earn_uw bcp_00_earn_uw ///
using "$tables/Table A2.tex", replace booktabs b(3) se(3) nomtitles keep(lmw) ///
varlabels(lmw "Log wages") nonote noobs star(* 0.10 ** 0.05 *** 0.01) width(\hsize) ///
mgroups("1990-2019" "1990-2016" "2000-2016", pattern(1 0 0 1 0 0 1 0 0) span ///
prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cmidrule(lr){@span})) ///
postfoot( ) ///
prehead(\begin{table}[h!]\centering ///
	\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}  ///
	\caption{MW effects on log average earnings and log employment in restaurants: TWFE estimates for different samples and specifications using quarterly QCEW data \label{tab:twfeqcewqtr}}  ///
	\footnotesize ///
	\begin{tabular*}{\hsize}{@{\hskip\tabcolsep\extracolsep\fill}l*{9}{c}} \toprule) ///
posthead(\midrule \\ ///
	\multicolumn{10}{l}{\textbf{A. Unweighted}} \\ & & & \\)

esttab twfe1_emp_uw mscz_emp_uw bcp_emp_uw twfe1_16_emp_uw mscz_16_emp_uw ///
bcp_16_emp_uw twfe1_00_emp_uw mscz_00_emp_uw bcp_00_emp_uw /// 
using "$tables/Table A2.tex", append booktabs b(3) se(3) nomtitles keep(lmw) ///
varlabels(lmw "Log employment") nonote noobs nonum star(* 0.10 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab twfe1_owe_uw mscz_owe_uw bcp_owe_uw twfe1_16_owe_uw mscz_16_owe_uw ///
bcp_16_owe_uw twfe1_00_owe_uw mscz_00_owe_uw bcp_00_owe_uw /// 
using "$tables/Table A2.tex", append booktabs b(3) se(3) nomtitles keep(learn75) ///
varlabels(learn75 "OWE") nonote noobs nonum star(* 0.10 ** 0.05 *** 0.01) width(\hsize) ///
prehead( ) posthead( ) postfoot( ) ///

esttab twfe1_earn_w mscz_earn_w bcp_earn_w twfe1_16_earn_w mscz_16_earn_w ///
bcp_16_earn_w twfe1_00_earn_w mscz_00_earn_w bcp_00_earn_w ///
using "$tables/Table A2.tex", append booktabs b(3) se(3) nomtitles keep(lmw) ///
varlabels(lmw "Log wages") nonote noobs nonum star(* 0.10 ** 0.05 *** 0.01) width(\hsize) ///
prehead(\multicolumn{10}{l}{\textbf{B. Weighted by population}} ///
\\ & & & \\) postfoot( ) posthead( )

esttab twfe1_emp_w mscz_emp_w bcp_emp_w twfe1_16_emp_w mscz_16_emp_w ///
bcp_16_emp_w twfe1_00_emp_w mscz_00_emp_w bcp_00_emp_w /// 
using "$tables/Table A2.tex", append booktabs b(3) se(3) nomtitles keep(lmw) ///
varlabels(lmw "Log employment") nonote noobs nonum star(* 0.10 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab twfe1_owe_w mscz_owe_w bcp_owe_w twfe1_16_owe_w mscz_16_owe_w ///
bcp_16_owe_w twfe1_00_owe_w mscz_00_owe_w bcp_00_owe_w ///
using "$tables/Table A2.tex", append booktabs b(3) se(3) nomtitles keep(learn75) ///
varlabels(learn75 "OWE") nonote noobs nonum star(* 0.10 ** 0.05 *** 0.01) width(\hsize) ///
stats(N gap fe czp_fe bcp_fe gap samples cz_state_sample mscz_sample bcp_sample, ///
labels("\textbf{N}" " " "\textbf{Fixed effects}" "MSCZ pair-year" "BC pair-year" ///
 " " "\textbf{Sample}" "All CZ-state" "MSCZ pairs" "Border county pairs") ///
fmt(%9.0fc)) /// 
prehead( ) posthead( ) ///
postfoot( ///
\hline\hline ///
\end{tabular*} ///
{\centering ///
\caption*{\begin{footnotesize} ///
\textit{Notes:} Estimated using specification described in equation \ref{eq:TWFE_logMW} and quarterly data from Quarterly Census of Employment and Wages data. Columns (1)-(3) use the years 1990-2019, (4)-(6) use 1990-2016, (7)-(9) use 2000-2016. Columns (1), (4), and (7) use the sample of all commuting-zones-by-state, and include CZ-state and year fixed effects. Columns (2), (5), and (8) use multi-state commuting-zone-by-state pairs sample and include fixed effects for CZ-state (repeated if a CZ-state is part of multiple pairs) and pair-year fixed effects. Columns (3), (6), and (9) similarly use the sample of border county pairs and include fixed effects for border counties (each time a county is in a pair) and pair-year fixed effects. Outcomes include log weekly earnings, log employment, and own wage elasticity (OWE). OWE is the IV estimate from regressing log employment on log earnings instrumented by log minimum wage. OWE estimates are only reported when there is a strong first-stage effect. Estimates in Panel A are unweighted, while estimates in Panel B are weighted using the working age population. All specifications include log earnings/log employment outside of the restaurant sector, and working-age population as control variables. Standard errors, reported in parentheses, are clustered at the state level. Stars indicate statistical significance as follows: sym{*} \(p<0.10\), \sym{**} \(p<0.05\), \sym{***} \(p<0.01\) ///
\end{footnotesize}}} ///
\end{table} ///
) ///
substitute("\_" "_")


************************************************
* Use quarterly QCEW, collapsed to annual lvl
************************************************

clear all

************************************************
* Loading different samples
************************************************
* 1. CZ-state
frame create twfe1
frame change twfe1

use "$clean/qcew/cz_state_sample_qtr_annual.dta", clear

* creating frames for sub-periods

frame copy twfe1 twfe1_00
frame copy twfe1 twfe1_16

frame twfe1_00: keep if inrange(year,2000,2016)
frame twfe1_16: keep if year <= 2016


* 2. MSCZ

frame create mscz
frame change mscz

use "$clean/qcew/mscz_sample_qtr_annual.dta", clear

* creating frames for sub-periods
frame copy mscz mscz_00
frame copy mscz mscz_16

frame mscz_00: keep if inrange(year,2000,2016)
frame mscz_16: keep if year <= 2016


* 3. BCP

frame create bcp
frame change bcp

use "$clean/qcew/bcp_sample_qtr_annual.dta", clear

* creating frames for sub-periods
frame copy bcp bcp_00
frame copy bcp bcp_16

frame bcp_00: keep if inrange(year,2000,2016)
frame bcp_16: keep if year <= 2016


************************************************
* TWFE regressions
************************************************

foreach frame in twfe1 twfe1_00 twfe1_16 {
	frame `frame' {
		eststo `frame'_earn_uw: reghdfe learn75 lmw learn_other lpop, a(czstate year) cluster(statefips)
		eststo `frame'_emp_uw: reghdfe lemp75 lmw lemp_other lpop, a(czstate year) cluster(statefips)
		eststo `frame'_owe_uw: ivreghdfe lemp75 (learn75 = lmw) learn_other lemp_other lpop, a(czstate year) cluster(statefips)
		
		eststo `frame'_earn_w: reghdfe learn75 lmw learn_other lpop [aw=pop], a(czstate year) cluster(statefips)
		eststo `frame'_emp_w: reghdfe lemp75 lmw lemp_other lpop [aw=pop], a(czstate year) cluster(statefips)
		eststo `frame'_owe_w: ivreghdfe lemp75 (learn75 = lmw) learn_other lemp_other lpop [aw=pop], a(czstate year) cluster(statefips)

		estadd local fe " "
		estadd local czp_fe " "
		estadd local bcp_fe " "
		estadd local gap " "
		estadd local samples " "
		estadd local cz_state_sample "Y"
		estadd local mscz_sample " "
		estadd local bcp_sample " "	
	}
}



foreach frame in bcp bcp_00 bcp_16 {
	frame `frame' {
		eststo `frame'_earn_uw: reghdfe learn75 lmw learn_other lpop, a(pair_id_county pair_id_num##year) cluster(statefips)
		eststo `frame'_emp_uw: reghdfe lemp75 lmw lemp_other lpop, a(pair_id_county pair_id_num##year) cluster(statefips)
		eststo `frame'_owe_uw: ivreghdfe lemp75 (learn75 = lmw) learn_other lemp_other lpop, a(pair_id_county pair_id_num##year) cluster(statefips)
		
		eststo `frame'_earn_w: reghdfe learn75 lmw learn_other lpop [aw=pop], a(pair_id_county pair_id_num##year) cluster(statefips)
		eststo `frame'_emp_w: reghdfe lemp75 lmw lemp_other lpop [aw=pop], a(pair_id_county pair_id_num##year) cluster(statefips)
		eststo `frame'_owe_w: ivreghdfe lemp75 (learn75 = lmw) learn_other lemp_other lpop [aw=pop], a(pair_id_county pair_id_num##year) cluster(statefips)

		estadd local fe " "
		estadd local czp_fe " "
		estadd local bcp_fe "Y"
		estadd local gap " "
		estadd local samples " "
		estadd local cz_state_sample " "
		estadd local mscz_sample " "
		estadd local bcp_sample "Y"	
	}
}



foreach frame in mscz mscz_00 mscz_16 {
	frame `frame' {
		eststo `frame'_earn_uw: reghdfe learn75 lmw learn_other lpop, a(pair_id_czstate pair_id_num##year) cluster(statefips)
		eststo `frame'_emp_uw: reghdfe lemp75 lmw lemp_other lpop, a(pair_id_czstate pair_id_num##year) cluster(statefips)
		eststo `frame'_owe_uw: ivreghdfe lemp75 (learn75 = lmw) learn_other lemp_other lpop, a(pair_id_czstate pair_id_num##year) cluster(statefips)
		
		eststo `frame'_earn_w: reghdfe learn75 lmw learn_other lpop [aw=pop], a(pair_id_czstate pair_id_num##year) cluster(statefips)
		eststo `frame'_emp_w: reghdfe lemp75 lmw lemp_other lpop [aw=pop], a(pair_id_czstate pair_id_num##year) cluster(statefips)
		eststo `frame'_owe_w: ivreghdfe lemp75 (learn75 = lmw) learn_other lemp_other lpop [aw=pop], a(pair_id_czstate pair_id_num##year) cluster(statefips)
		
		estadd local fe " "
		estadd local czp_fe "Y"
		estadd local bcp_fe " "
		estadd local gap " "
		estadd local samples " "
		estadd local cz_state_sample " "
		estadd local mscz_sample "Y"
		estadd local bcp_sample " "	
	}
}

* Output twfe table
esttab twfe1_earn_uw mscz_earn_uw bcp_earn_uw twfe1_16_earn_uw mscz_16_earn_uw ///
bcp_16_earn_uw twfe1_00_earn_uw mscz_00_earn_uw bcp_00_earn_uw ///
using "$tables/Table A3.tex", replace booktabs b(3) se(3) nomtitles keep(lmw) ///
varlabels(lmw "Log wages") nonote noobs star(* 0.10 ** 0.05 *** 0.01) width(\hsize) ///
mgroups("1990-2019" "1990-2016" "2000-2016", pattern(1 0 0 1 0 0 1 0 0) span ///
prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cmidrule(lr){@span})) ///
postfoot( ) ///
prehead(\begin{table}[h!]\centering ///
	\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}  ///
	\caption{TWFE estimates for different samples and specifications,  quarterly QCEW data collapsed to annual level \label{tab:twfeqcewqtrannual}}  ///
	\footnotesize ///
	\begin{tabular*}{\hsize}{@{\hskip\tabcolsep\extracolsep\fill}l*{9}{c}} \toprule) ///
posthead(\midrule \\ ///
	\multicolumn{10}{l}{\textbf{A. Unweighted}} \\ & & & \\)

esttab twfe1_emp_uw mscz_emp_uw bcp_emp_uw twfe1_16_emp_uw mscz_16_emp_uw ///
bcp_16_emp_uw twfe1_00_emp_uw mscz_00_emp_uw bcp_00_emp_uw /// 
using "$tables/Table A3.tex", append booktabs b(3) se(3) nomtitles keep(lmw) ///
varlabels(lmw "Log employment") nonote noobs nonum star(* 0.10 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab twfe1_owe_uw mscz_owe_uw bcp_owe_uw twfe1_16_owe_uw mscz_16_owe_uw ///
bcp_16_owe_uw twfe1_00_owe_uw mscz_00_owe_uw bcp_00_owe_uw /// 
using "$tables/Table A3.tex", append booktabs b(3) se(3) nomtitles keep(learn75) ///
varlabels(learn75 "OWE") nonote noobs nonum star(* 0.10 ** 0.05 *** 0.01) width(\hsize) ///
prehead( ) posthead( ) postfoot( ) ///

esttab twfe1_earn_w mscz_earn_w bcp_earn_w twfe1_16_earn_w mscz_16_earn_w ///
bcp_16_earn_w twfe1_00_earn_w mscz_00_earn_w bcp_00_earn_w ///
using "$tables/Table A3.tex", append booktabs b(3) se(3) nomtitles keep(lmw) ///
varlabels(lmw "Log wages") nonote noobs nonum star(* 0.10 ** 0.05 *** 0.01) width(\hsize) ///
prehead(\multicolumn{10}{l}{\textbf{B. Weighted by population}} ///
\\ & & & \\) postfoot( ) posthead( )

esttab twfe1_emp_w mscz_emp_w bcp_emp_w twfe1_16_emp_w mscz_16_emp_w ///
bcp_16_emp_w twfe1_00_emp_w mscz_00_emp_w bcp_00_emp_w /// 
using "$tables/Table A3.tex", append booktabs b(3) se(3) nomtitles keep(lmw) ///
varlabels(lmw "Log employment") nonote noobs nonum star(* 0.10 ** 0.05 *** 0.01) ///
width(\hsize) prehead( ) posthead( ) postfoot( )

esttab twfe1_owe_w mscz_owe_w bcp_owe_w twfe1_16_owe_w mscz_16_owe_w ///
bcp_16_owe_w twfe1_00_owe_w mscz_00_owe_w bcp_00_owe_w ///
using "$tables/Table A3.tex", append booktabs b(3) se(3) nomtitles keep(learn75) ///
varlabels(learn75 "OWE") nonote noobs nonum star(* 0.10 ** 0.05 *** 0.01) width(\hsize) ///
stats(N gap fe czp_fe bcp_fe gap samples cz_state_sample mscz_sample bcp_sample, ///
labels("\textbf{N}" " " "\textbf{Fixed effects}" "MSCZ pair-year" "BC pair-year" ///
 " " "\textbf{Sample}" "All CZ-state" "MSCZ pairs" "Border county pairs") ///
fmt(%9.0fc)) /// 
prehead( ) posthead( ) ///
postfoot( ///
\hline\hline ///
\end{tabular*} ///
{\centering ///
\caption*{\begin{footnotesize} ///
\textit{Notes:} Estimated using specification described in equation \ref{eq:TWFE_logMW} and quarterly data from Quarterly Census of Employment and Wages data. Columns (1)-(3) use the years 1990-2019, (4)-(6) use 1990-2016, (7)-(9) use 2000-2016. Columns (1), (4), and (7) use the sample of all commuting-zones-by-state, and include CZ-state and year fixed effects. Columns (2), (5), and (8) use multi-state commuting-zone-by-state pairs sample and include fixed effects for CZ-state (repeated if a CZ-state is part of multiple pairs) and pair-year fixed effects. Columns (3), (6), and (9) similarly use the sample of border county pairs and include fixed effects for border counties (each time a county is in a pair) and pair-year fixed effects. Outcomes include log weekly earnings, log employment, and own wage elasticity (OWE). OWE is the IV estimate from regressing log employment on log earnings instrumented by log minimum wage. OWE estimates are only reported when there is a strong first-stage effect. Estimates in Panel A are unweighted, while estimates in Panel B are weighted using the working age population. All specifications include log earnings/log employment outside of the restaurant sector, and working-age population as control variables. Standard errors, reported in parentheses, are clustered at the state level. Stars indicate statistical significance as follows: sym{*} \(p<0.10\), \sym{**} \(p<0.05\), \sym{***} \(p<0.01\) ///
\end{footnotesize}}} ///
\end{table} ///
) ///
substitute("\_" "_")



